﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using System.Diagnostics;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

namespace SSISFromCode.Events
{
    internal class ComponentEvents: IDTSComponentEvents100
    {

        private ImportMessages _messages;

        public ComponentEvents( ImportMessages messages )
        {
            _messages = messages;
        }

        public void FireCustomEvent( string eventName, string eventText, ref object[] arguments, string subComponent, ref bool fireAgain )
        {
            //Console.WriteLine( "CustomEvent: {0}", eventText );
            //fireAgain = true;
        }

        public void FireInformation( int informationCode, string subComponent, string description, string helpFile, int helpContext, ref bool fireAgain )
        {
            _messages.Add( IMPORT_MESSAGES.INFORMATION, subComponent, description );
        }

        /// <summary>
        /// You'd think the Data Task Flow would fire this sucker, but it doesn't.
        /// If you're running a package in the designer, you will see row import progress near the pipe connecting your data flow components.
        /// That is apparently totally unrelated to this event...
        /// </summary>
        /// <param name="progressDescription"></param>
        /// <param name="percentComplete"></param>
        /// <param name="progressCountLow"></param>
        /// <param name="progressCountHigh"></param>
        /// <param name="subComponent"></param>
        /// <param name="fireAgain"></param>
        public void FireProgress( string progressDescription, int percentComplete, int progressCountLow, int progressCountHigh, string subComponent, ref bool fireAgain )
        {
            _messages.Add( IMPORT_MESSAGES.PROGRESS, subComponent, progressDescription, Convert.ToString(percentComplete) );
            fireAgain = true;
        }

        public bool FireQueryCancel()
        {
            throw new NotImplementedException();
        }

        public void FireWarning( int warningCode, string subComponent, string description, string helpFile, int helpContext )
        {
            _messages.Add( IMPORT_MESSAGES.WARNING, subComponent, description );
        }

        public void FireBreakpointHit( IDTSBreakpointTarget100 pBreakpointTarget )
        {
            throw new NotImplementedException();
        }

        public void FireError( int ErrorCode, string SubComponent, string Description, string HelpFile, int HelpContext, out bool pbCancel )
        {
            _messages.Add( IMPORT_MESSAGES.ERROR, SubComponent, Description );
            pbCancel = true;
        }

        public void FireQueryCancel( out bool pbCancel )
        {
            throw new NotImplementedException();
        }

    }
}
